package com.ego.product.vo.order;

import com.ego.common.vo.member.MemberReceiveAddressVo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * @program: ego
 * @description: 订单确认页信息Vo
 * @author: KamTang
 * @create: 2022-12-20 13:07
 **/
@Setter
@Getter
public class OrderConfirmVo {
    /**
     * 收货地址
     */
    private List<MemberReceiveAddressVo> addressVos;

    /**
     * 所有选中的购物项
     */
    private List<OrderItemVo> orderItems;

    /**
     * 订单防重令牌 —— 防止用户重复提交
     */

    private String orderToken;

    public BigDecimal getTotalAmount() {
        BigDecimal sum = BigDecimal.ZERO;
        if (!CollectionUtils.isEmpty(orderItems)) {
            for (OrderItemVo orderItem : orderItems) {
                BigDecimal multiply = orderItem.getPrice().multiply(new BigDecimal(orderItem.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        return getTotalAmount();
    }

    @Setter
    @Getter
    public static class OrderItemVo {
        private Long skuId;
        private Boolean selected;
        private String title;
        private String image;
        private List<String> skuAttrs;
        private BigDecimal price;
        private Integer count;
        private BigDecimal totalPrice;
        /**
         * 是否参与促销 0:普通商品，1：活动商品
         */
        private Integer promotion = 0;
    }

}
